package fr.cephb.joperon.swing;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenu;

import javax.swing.AbstractAction;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import fr.cephb.joperon.core.entities.PrjDna;
import fr.cephb.swing.GenericTableModel;

/**
 * PrjFinFrame
 * @author lindenb
 *
 */
public class PrjDnaFrame extends  OperonFrame
	{
	private static final long serialVersionUID = 1L;

	private static class Model
		extends GenericTableModel<String>
		{
		private static final long serialVersionUID = 1L;
		
		public Model()
			{
			super();
			}
		
		public Model(String array[])
			{
			super(array);
			}
		
		@Override
		public int getColumnCount() {
			return 1;
			}
		
		@Override
		public String getColumnName(int columnIndex) {
			switch(columnIndex)
				{
				case 0: return "DNA-ID";
				}
			return null;
			}
		
		@Override
		public Object getValueOf(String item, int columnIndex) {
			switch(columnIndex)
				{
				case 0: return item;
				}
			return null;
			}
		}

	private Model tableModel;
	private JTable table;

	public PrjDnaFrame(OperonGUI operon,PrjDna prjdna)
		{
		super(operon,"Project DNA:" +prjdna.getAcn());
		
		AbstractAction action= new AbstractAction("Projects Inputs")
			{
			private static final long serialVersionUID = 1L;
			@Override
			public void actionPerformed(ActionEvent e)
				{
				select();
				}
			};

		JMenu menu= new JMenu("Action");
		menu.add(action);
		getJMenuBar().add(menu);
		
		this.tableModel= new Model( prjdna.getSet().split("[\\|]"));
		this.table= new JTable(this.tableModel);
		
		super.content.add(new JScrollPane(this.table),BorderLayout.CENTER);
		
		
		
		this.table.addMouseListener(new MouseAdapter()
			{
			@Override
			public void mouseClicked(MouseEvent e) {
				if(e.getClickCount()<2) return;
				select();
				}
			});
		
		selectionListen(action,this.table);
		}
	
	
	
	private void select()
		{
		int i=table.getSelectedRow();
		i= table.convertRowIndexToModel(i);

		}
	
	
	}
